class D_webSocket{
    constructor(url, protocols){
        this.status = ''
        this.url = url
        this.protocols = protocols
        this.webSocket = {}
    }

    connect(){
        let ws = new WebSocket(this.url, this.protocols)
        this.webSocket = ws
    }

    on(eventName, callback = ()=>{}){
        switch (eventName) {
            case '':
            case undefined:
            case null:
                // 监听所有
                break;
            case 'close':
                this.webSocket.onclose = ()=>{callback(...arguments)}
                break
            case 'error':
                this.webSocket.onerror = ()=>{callback(...arguments)}
                break
            case 'message':
                this.webSocket.onmessage = ()=>{callback(...arguments)}
                break
            case 'open':
                this.webSocket.onopen = ()=>{callback(...arguments)}
                break
            default:
                this.webSocket.onclose = ()=>{callback(...arguments)}
                this.webSocket.onerror = ()=>{callback(...arguments)}
                this.webSocket.onmessage = ()=>{callback(...arguments)}
                this.webSocket.onopen = ()=>{callback(...arguments)}
                break;
        }
    }

    send(data){
        
    }
}

export default D_webSocket